#include "comm.hpp"

int main()
{
    int key = getKey();
    printf("key: 0x%x\n", key);

    int shmid = getSHM(key);
    std::cout << "shmid: " << shmid << std::endl;
    
    //client和server返回的地址不一样，因为它们返回的是虚拟地址，通过各自的页表可以找到同一块共享内存
    void *start = attachSHM(shmid);
    std::cout << "start address: " << start << std::endl;

    int cnt=1;
    while(1)
    {
        snprintf((char*)start, MAX_SIZE-1, "你好server，我是client。pid[%d]，消息号[%d]\n",getpid(),cnt++);
        sleep(2);
    }

    detachSHM(start);

    return 0;
}

